package com.kingwood.algorithm.test200;


import java.util.Arrays;
import java.util.Scanner;

// 结对编程
//https://fcqian.blog.csdn.net/article/details/134725138
public class JieDuiBianCheng {

    public static int getResultByBaoLi(int n, int[] arr) {
        int ans = 0;
        for (int i=1; i<n-1; i++) {
            int mid = arr[i];
            int leftBigger = 0;
            int leftSmaller = 0;
            for (int j=0; j<i; j++) {
                if (mid > arr[j]) {
                    leftSmaller++;
                }
                if (mid < arr[j]) {
                    leftBigger++;
                }
            }

            int rightBigger = 0;
            int rightSmaller = 0;
            for (int k = i + 1; k < n; k++) {
                if (mid > arr[k]) {
                    rightSmaller++;
                }
                if (mid < arr[k]) {
                    rightBigger++;
                }
            }

            ans += (leftSmaller * rightBigger) + (leftBigger * rightSmaller);
        }

        return ans;
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] arr = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        int ans1 = getResultByBaoLi(n, arr);
        System.out.println(ans1);
    }
}
